// use localStorage to store the authority info, which might be sent from server in actual project.
// 获取用户权限
export function getAuthority(str) {
  // return localStorage.getItem('antd-pro-authority') || ['admin', 'user'];

  //   角色获取
  const authorityString = typeof str === 'undefined' ? localStorage.getItem('joyPermissions') : str; // authorityString could be admin, "admin", ["admin"]
  let authority;

  try {
    if (authorityString) {
      authority = JSON.parse(authorityString); // 如果authorityString是JSON格式字符串
    }
  } catch (e) {
    authority = authorityString;
  }

  if (typeof authority === 'string') {
    return [authority];
  } // preview.pro.ant.design only do not use in your production.
  // preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。

  if (!authority && ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
    return [];
  }
  //   最终返回角色数组可以来自入参 localstorage 或者默认是 ['admin']
  return authority;
}
export function setAuthority(authority) {
  const proAuthority = typeof authority === 'string' ? [authority] : authority;
  return localStorage.setItem('joyPermissions', JSON.stringify(proAuthority));
}
